package com.dayaokeji.rhythmschoolstudent.client.common.exam.subject_type;

import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.dayaokeji.rhythmschoolstudent.client.common.base.common.BaseFragment;
import com.dayaokeji.rhythmschoolstudent.client.common.exam.adapter.SubjectImgAdapter;
import com.dayaokeji.rhythmschoolstudent.client.common.exam.subject_type.utils.AnswerCallback;
import com.dayaokeji.rhythmschoolstudent.client.common.exam.subject_type.utils.SubjectTypeUtil;
import com.dayaokeji.rhythmschoolstudent.client.common.ShowBigImageActivity;
import com.dayaokeji.server_api.domain.SubjectAnswer;

/**
 * Created by Gorden on 2018/5/4.
 */
public abstract class BaseSubjectFragment extends BaseFragment {

    protected static final String EXTRA_EXAM_ENTITY = "exam_entity";
    private boolean isExamResult = false;
    private boolean isShowResult = false;
    private int totalScore;
    private float score;

    protected String getSubjectTypeStr(int type) {
        String typeStr = "";
        switch (type) {
            case SubjectTypeUtil.SINGLE_CHOOSE:
                typeStr = "单选";
                break;
            case SubjectTypeUtil.MULTIPLE_CHOOSE:
                typeStr = "多选";
                break;
            case SubjectTypeUtil.BLANK_SUBJECT:
                typeStr = "填空";
                break;
            case SubjectTypeUtil.JUDGMENT_PROBLEM:
                typeStr = "判断";
                break;
            case SubjectTypeUtil.QUESTION_AND_ANSWER:
                typeStr = "问答";
                break;
        }
        return "题型："+typeStr;
    }

    /**
     * 查看大图
     * @param subjectImgAdapter
     */
    protected void setNavigationShowImage(SubjectImgAdapter subjectImgAdapter) {
        if (subjectImgAdapter != null) {
            subjectImgAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
                @Override
                public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                    final Integer imgId = (Integer) adapter.getData().get(position);
                    ShowBigImageActivity.navigation(getActivity(),imgId);
                }
            });
        }
    }

    /**
     * 是否显示考试结果
     * @param isExamResult
     * @return
     */
    public BaseSubjectFragment setShowExamResult(boolean isExamResult) {
        this.isExamResult = isExamResult;
        return this;
    }

    public BaseSubjectFragment setShowResult(boolean showResult) {
        isShowResult = showResult;
        return this;
    }

    public boolean isShowResult() {
        return isShowResult;
    }

    public boolean isExamResult() {
        return isExamResult;
    }


    protected void callbackResult(SubjectAnswer subjectAnswer) {
        if (getActivity() != null) {
            if (getActivity() instanceof AnswerCallback) {
                ((AnswerCallback) getActivity()).callback(subjectAnswer);
            }
        }
    }


    public BaseSubjectFragment setScore(int totalScore,float score) {
        this.totalScore = totalScore;
        this.score = score;
        return this;
    }

    public float getScore() {
        return score;
    }

    public int getTotalScore() {
        return totalScore;
    }
}
